package com.msmall.community.question.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.msmall.base.cache.CacheFactory;
import com.msmall.base.model.BaseObject;
import com.msmall.base.util.Constants;
import com.msmall.base.util.StringUtil;
import com.msmall.community.common.CascadeCollection;
import com.msmall.community.dpt.model.Segment;

@Entity
@Table(name="klg_question")
public class Question extends BaseObject{

	private static final long serialVersionUID = 2192943782211142730L;

	@Id
	@Column(name="question_id")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long questionid;
	
	@Column(name="user_id")
	private Long userid;
	
	@Column(name="nickname")
	private String nickname;
	
	/**
	 * 问题分类
	 */
	@Column(name="type")
	private Long type;
	
	/**
	 * 是否已经结束 ConstantDB.QUESTION_TERMINAL_YES
	 */
	@Column(name="terminal")
	private Short terminal;
	
	/**
	 * 回答数
	 */
	@Column(name="answer_amount")
	private Integer answerAmount;
	
	/**
	 * 悬赏分数
	 */
	@Column(name="score")
	private Integer score;
	
	/**
	 * 到期时间
	 */
	@Column(name="due_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date dueTime;

	@Column(name="signature")
	private String signature;

	@Column(name="title")
	private String title;
	
	@Column(name="file_path")
	private String filePath; // 文件路径

	@Column(name="file_name")
	private String fileName; //文件名称
	
	@Column(name="file_ext")
	private String fileExt; // 文件扩展名
	
	@Column(name="file_flag")
	private String fileFlag; // 文件标识，目前生产了什么文件
	
	@Column(name="content")
	private String content;

	@Column(name="click_amount")
	private Integer clickAmount;

	@Column(name="create_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date createTime;

	/**
	 * 作者的最后修改日期
	 */
	@Column(name="last_modify_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastModifyTime;
	
	/**
	 * 最后回复日期
	 */
	@Column(name="last_thread_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastAnswerTime;
	
	@Column(name="enabled")
	private Short enabled;

	/**
	 * WWW 1 , WAP 2
	 */
	@Column(name="source")
	private Short source;

	/**
	 * 转载 1， 原创2
	 * Constantdb.FROM_TRANSFER
	 */
	@Column(name="original")
	private Short original;

	/**
	 * 是否允许回复
	 */
	@Column(name="reply")
	private Short reply;

	@Column(name="notice")
	private Short notice;
	
	/**
	 * 返回type name.
	 */
	public String getTypeName(){
		try{
			CascadeCollection<Segment> cs = (CascadeCollection<Segment>) CacheFactory.getInstance().getCache(Constants.CACHE_NAME_COMMON).get(Constants.CACHE_KEY_SEGMENT_CASCADECOLLECTION);
			return cs.getAllDatas().get(type).getCurrent().getTitle();
		}catch(Exception e){
			
		}
		return "哈哈";
	}
	/**
	 * 返回content前15个字符
	 */
	public String getContent15(){
		return StringUtil.getChineseSubString(content, 15, "…");
	}
	/**
	 * 返回content前10个字符
	 */
	public String getContent10(){
		return StringUtil.getChineseSubString(content, 10, "…");
	}
	public String getContent20(){
		return StringUtil.getChineseSubString(content, 20, "…");
	}
	public Long getQuestionid() {
		return questionid;
	}

	public void setQuestionid(Long questionid) {
		this.questionid = questionid;
	}

	public Long getUserid() {
		return userid;
	}

	public void setUserid(Long userid) {
		this.userid = userid;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public Long getType() {
		return type;
	}

	public void setType(Long type) {
		this.type = type;
	}

	public Integer getAnswerAmount() {
		return answerAmount;
	}

	public void setAnswerAmount(Integer answerAmount) {
		this.answerAmount = answerAmount;
	}

	public Integer getScore() {
		return score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	public Date getDueTime() {
		return dueTime;
	}

	public void setDueTime(Date dueTime) {
		this.dueTime = dueTime;
	}

	public String getSignature() {
		return signature;
	}

	public void setSignature(String signature) {
		this.signature = signature;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFileExt() {
		return fileExt;
	}

	public void setFileExt(String fileExt) {
		this.fileExt = fileExt;
	}

	public String getFileFlag() {
		return fileFlag;
	}

	public void setFileFlag(String fileFlag) {
		this.fileFlag = fileFlag;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Integer getClickAmount() {
		return clickAmount;
	}

	public void setClickAmount(Integer clickAmount) {
		this.clickAmount = clickAmount;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getLastModifyTime() {
		return lastModifyTime;
	}

	public void setLastModifyTime(Date lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}

	public Date getLastAnswerTime() {
		return lastAnswerTime;
	}

	public void setLastAnswerTime(Date lastAnswerTime) {
		this.lastAnswerTime = lastAnswerTime;
	}

	public Short getEnabled() {
		return enabled;
	}

	public void setEnabled(Short enabled) {
		this.enabled = enabled;
	}

	public Short getSource() {
		return source;
	}

	public void setSource(Short source) {
		this.source = source;
	}

	public Short getOriginal() {
		return original;
	}

	public void setOriginal(Short original) {
		this.original = original;
	}

	public Short getReply() {
		return reply;
	}

	public void setReply(Short reply) {
		this.reply = reply;
	}

	public Short getNotice() {
		return notice;
	}

	public void setNotice(Short notice) {
		this.notice = notice;
	}

	public Short getTerminal() {
		return terminal;
	}

	public void setTerminal(Short terminal) {
		this.terminal = terminal;
	}

	@Override
	public boolean equals(Object o) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}

}
